package com.clubs.coding.Service.Impl;

import com.clubs.coding.Service.SynthesizeService;
import com.clubs.coding.exception.ImoocMallException;
import com.clubs.coding.exception.ImoocMallExceptionEnum;
import com.clubs.coding.model.dao.AthLeaveMapper;
import com.clubs.coding.model.pojo.AthLeave;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SynthesizeServiceImpl implements SynthesizeService {
@Autowired
    AthLeaveMapper athLeaveMapper;
    /**
     * 后台请假列表
     * */
@Override
public PageInfo list(Integer pageNum, Integer pageSize,Integer type){
    PageHelper.startPage(pageNum, pageSize,"create_time desc ");
    List<AthLeave> athLeaves = athLeaveMapper.selectByIsLeave(type);
    PageInfo pageInfo = new PageInfo(athLeaves);
    pageInfo.setList(athLeaves);
   return pageInfo;
}
/**
 * 后台请假审核
 * */
@Override
public void check_leave(Integer id, Integer type){
    AthLeave athLeave = new AthLeave();
    athLeave.setLeaveId(id);

    athLeave.setIsLeave(type);
    athLeave.setUpdateTiem(new Date());
    int i = athLeaveMapper.updateByPrimaryKeySelective(athLeave);
    if (i==0) {
        throw new ImoocMallException(ImoocMallExceptionEnum.LEAVE_NULL);
    }

}
}
